<template>
  <div id="reset">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="满" prop="full">
        <el-input v-model="ruleForm.full"></el-input>
      </el-form-item>
      <el-form-item label="减" prop="decrease">
        <el-input v-model="ruleForm.decrease"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">确认修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {requestGet, requestPost} from "../../../../network/request";

  export default {
    props: ['id'],
    name: "resetUser",
    data(){
      return {
        id: '',
        ruleForm: {
          full: null,
          decrease: null,
        },
        rules: {
          full: [
            { required: true, message: '请输入满金额', trigger: 'blur' },
          ],
          decrease: [
            { required: true, message: '请输入减金额', trigger: 'blur' },
          ],
        }
      }
    },
    methods: {
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            requestPost({
              url: 'activity/update',
              data: {
                activityId:this.id,
                full: this.ruleForm.full,
                decrease: this.ruleForm.decrease,
              }
            }).then(res=>{
              alert("修改成功");
              this.$router.replace("/user/userList");
            });

          } else {
            alert("修改失败");
            return false;
          }
        });
      },
    },
    mounted() {
      console.log(this.id);
      requestPost({
        url: 'activity/search',
        data: {
          activityId: this.id
        }
      }).then(
        response=>{
          this.ruleForm= response.data.activity;
        });

    },

  }
</script>

<style scoped>
  .demo-ruleForm{
    width: 70%;
  }
  #reset{
    text-align: center;
    margin: 0 auto;
    width: 50%;
    padding-top: 5%;
  }
</style>
